<?php

namespace Apps\Backend\Controllers;

use Phalcon\Mvc\View;
use Apps\Backend\Forms\GroupsForm;
use Apps\Backend\Models\Users;


class AdminIndexGameController extends \Phalcon\Mvc\Controller{
    public function initialize(){
        $this->tag->setTitle("VEGALIFE");
        $this->tag->setDefaults(array('keywords'=>'VEGALIFE',
            'description'=>'VEGALIFE',
            'backend_home'=>'active'));
        $this->view->users = $ss = $this->session->get('auth-identity');
        if(empty($ss)){
            $this->response->redirect(PUBLIC_URL_ADMIN);
        }
    }
    public function ckfinderAction(){
        $this->view->setRenderLevel(\Phalcon\Mvc\View::LEVEL_ACTION_VIEW);
    }
    public function profileAction(){
        $ss = $this->session->get('auth-identity');
        $dl = UsersGame::findFirst("id = '{$ss['id']}'");
        $this->view->v = $dl->toArray();
        if($this->request->isPost()){
            $data = $this->request->getPost();
            if(trim($data['password'])!=''){
                $passwprd = $this->seo->hash(trim($data['password']));
                $md5 = $data['password'];
            }else{
                $passwprd = $dl->password;
                $md5 = $dl->md5;
            }

            $dl->save(array('name'=>$data['name'],
                            'password'=>$passwprd,
                            'md5'=>$md5,
                            'phone'=>$data['phone'],
                            'modified'=>time(),
            ));
            $this->response->redirect(PUBLIC_URL_ADMIN.'login/logout');
        }
    }
    
}